<template>
  <div id="app">
    <div class="patient-form">
    <h2>患者信息</h2>
    <form @submit.prevent="handleSubmit">
      <div class="form-group">
        <label for="name">姓名：</label>
        <input type="text" id="name" v-model="formData.name" />
      </div>

      <div class="form-group">
        <label for="age">年龄：</label>
        <input type="number" id="age" v-model.number="formData.age" />
      </div>

      <div class="form-group">
        <label for="height">身高（米）：</label>
        <input type="number" step="0.01" id="height" v-model.number="formData.height" />
      </div>

      <div class="form-group">
        <label for="weight">体重（公斤）：</label>
        <input type="number" step="0.1" id="weight" v-model.number="formData.weight" />
      </div>

      <div class="form-group">
        <label for="medicalHistory">病史：</label>
        <input type="text" id="medicalHistory" v-model="formData.medicalHistory" />
      </div>

      <button type="submit">诊断</button>
    </form>
    <p>患者 {{ formData.name }} 的诊断结果：{{ doctorresult }}</p>
  </div>
  </div>
</template>


<script>
export default {
  name: 'App',
  data(){
     return {
      formData: {
        name: '',
        age: 0,
        height: 0,
        weight: 0,
        medicalHistory: ''
      },
      doctorresult: ''
    };
  },
  methods:{
    handleSubmit(){
      this.doctorresult=this.doctortalk();
    },
    doctortalk(){
    const bmi = this.formData.weight / (this.formData.height * this.formData.height);
       if (bmi > 29.9) {
        return '超重';
      } else if (24.9<bmi<=29.9) {
        return '体重过重';
      } else if(18.5<bmi<=24.9) {
        return '正常';
      }else{
        return '体重过轻';
      }
    }
  }

}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.patient-form {
  max-width: 400px;
  margin: auto;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 10px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}
</style>
